package al.softsynergy.auk.data.ejbs;

import java.util.Date;
import java.util.List;

import javax.ejb.Stateful;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

import al.softsynergy.auk.data.entries.Ankesa;
import al.softsynergy.auk.data.entries.AnkesaLloj;

@Stateful
public class AukBean implements IAukBean {

	@PersistenceContext
	private EntityManager em;

	private String user;
	
	public void login(String user){
		this.user = user;
	}
	
	
	
	
	public Ankesa saveAnkesa(Ankesa ankesa){
		ankesa.setUser(this.user);
		ankesa.setDataRegj(new Date());
		return em.merge(ankesa);
	}
	
	public List<Ankesa> queryAnkesa(){
		List<Ankesa> list = em.createQuery("Select o from Ankesa o").getResultList();
		return list;
	}
	
	public List<AnkesaLloj> queryAnkesaLloj(){
		return em.createQuery("Select o from AnkesaLloj o").getResultList();
	}
	
	public List<Ankesa> queryAnkesa(String emri, String mbiemri){
		List<Ankesa> list = em.createQuery("Select o from Ankesa o where o.emri like :emri and o.mbiemri like :mbiemri ").setParameter("emri", emri).setParameter("mbiemri", mbiemri).getResultList();
		return list;
	}
	
}
